package zmee.bid.oa;

import com.alibaba.druid.support.logging.Log;
import com.alibaba.druid.support.logging.LogFactory;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.botp.BFTrackerServiceHelper;
import zmee.util.BosUtil;
import zmee.util.OARequestUtil;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @author lijiawang
* @Date 2022/11/10 16:30
* @Description:
*/
public class OAutil {
    private static Log logger = LogFactory.getLog(OAutil.class);
    private static OAutil initialize=new OAutil();

    public static OAutil getInitialize(){
        return initialize;
    }
    /**
     * 获取请求字段信息
     */
    public static Map<String, Object> getMainfieldMap(DynamicObject param) {
        String name = param.getDynamicObjectType().getName();
        DynamicObject single = BusinessDataServiceHelper.loadSingle(param.getPkValue(), name);
        Map<String, Object> map = new HashMap<>();
        getParameter(single,map);
        return map;
    }


    /**
    * 请求头信息
    */
    private static void getParameter(DynamicObject single, Map<String, Object> map){
        String name = single.getDynamicObjectType().getName();
        String billno = single.getString("billno");
//        long currentUserId = UserServiceHelper.getCurrentUserId();
//        DynamicObject user = BusinessDataServiceHelper.loadSingle(currentUserId, "bos_user");
//        DynamicObjectCollection entryentity = user.getDynamicObjectCollection("entryentity");
//        DynamicObject userOrg = initialize.getUserOrg(entryentity);
        switch (name){
            //标书编制
            case "src_biddoc":
                //项目启动单
                DynamicObject project = BusinessDataServiceHelper.loadSingle("src_project", "id", new QFilter[]{new QFilter("billno", QCP.equals, billno)});
                DynamicObject src_project = BusinessDataServiceHelper.loadSingle(project.getPkValue(), "src_project");
                String orgname = single.getString("org.name");
                String bidname=single.getString("bidname");
                String sourcetype=single.getString("sourcetype.name");
                StringBuilder stringBuilder=new StringBuilder();
                stringBuilder.append("【"+orgname+"】");
                stringBuilder.append("【"+sourcetype+"】");
                stringBuilder.append("【"+bidname+"】");
                stringBuilder.append("【"+billno+"】");
                stringBuilder.append("文件");
                map.put("bt",stringBuilder.toString());
                map.put("bh", billno);//编号
                map.put("sourcefrom", "优采云");//系统来源
                map.put("barcode", billno);//编号
                map.put("jgpmfs",initialize.jgpmfs(single.getString("taxtypepm")) );//编号
                map.put("zbxmmc", single.getString("bidname"));//招标项目名称
                map.put("tjr", single.getString("aosqr.oaid"));//提交人
                map.put("tjbm", single.getString("oaorg.oaid"));//部门
                //招标立项申请单
                String source = src_project.get("source.number").toString();
                DynamicObject demand = BusinessDataServiceHelper.loadSingle(source, "src_demand");
                boolean checkbox = demand.getBoolean("checkbox");
                BigDecimal projectbudget=new BigDecimal("0.00");
                BigDecimal moneys=new BigDecimal("0.00");
                if(!checkbox) {
                    //项目支出预算
                    DynamicObject id = demand.getDynamicObject("pro_approval");
                    DynamicObject outbudget = BusinessDataServiceHelper.loadSingle(id.getPkValue(),"pmas_outbudget");
                    DynamicObject pro = outbudget.getDynamicObject("project");
                    map.put("ssxmmc", pro.getString("name"));//所属项目名称
                    DynamicObject proid = BusinessDataServiceHelper.loadSingle(pro.getPkValue(), pro.getDynamicObjectType().getName());
                    DynamicObject group = proid.getDynamicObject("group");//项目分类编码
                    DynamicObject gro = BusinessDataServiceHelper.loadSingle(group.getPkValue(), group.getDynamicObjectType().getName());
                    DynamicObject parentid = gro.getDynamicObject("parent");
                    if("106".equals(parentid.getString("number"))) {
                        map.put("yslb", "4"); //预算类别
                    }else {
                        map.put("yslb",initialize.getYslb(group.getString("number"))); //预算类别
                    }
                    DynamicObject[] outbudgets = BusinessDataServiceHelper.load("pmas_outbudget", "id",
                            new QFilter[]{new QFilter("project.id", QCP.equals, pro.getPkValue()).and(new QFilter("billstatus", QCP.equals, "C"))});
                    logger.info("====outbudgets===="+outbudgets.length);
                    Map<String, Object> objectMap = initialize.getMoney(outbudgets);

                    logger.info("====demands===="+objectMap.get("sum"));
                    map.put("ssxmyzbxmsl", objectMap.get("sum"));//所属项目已招标项目数量
                    moneys = moneys.add((BigDecimal) objectMap.get("money"));
                    logger.info("====money===="+objectMap.get("money"));
                    logger.info("====moneys===="+moneys);
                    projectbudget=projectbudget.add(demand.getBigDecimal("projectbudget"));
                }else{
                    //获取上游单据
                    Map<String, HashSet<Long>> demandMap = BFTrackerServiceHelper.findSourceBills(demand.getDynamicObjectType().getName(), new Long[]{demand.getLong("id")});
                    HashSet<Long> set = demandMap.get(demand.getDynamicObjectType().getName());
                    StringBuffer proName=new StringBuffer();
                    String s="0";
                    Integer num=0;
                    for (Long id:set) {
                        DynamicObject setId = BusinessDataServiceHelper.loadSingle(id, demand.getDynamicObjectType().getName());
                        DynamicObject proval = setId.getDynamicObject("pro_approval");
                        DynamicObject outbudget = BusinessDataServiceHelper.loadSingle("pmas_outbudget", "id,project", new QFilter[]{new QFilter("id", QCP.equals, proval.getPkValue())});
                        DynamicObject pro = outbudget.getDynamicObject("project");
                        proName.append("【"+pro.getString("name")+"】");
                        s= pro.get("group.number").toString();//项目分类编码
                        DynamicObject[] outbudgets = BusinessDataServiceHelper.load("pmas_outbudget", "id",
                                new QFilter[]{new QFilter("project.id", QCP.equals, pro.getPkValue())
                                        .and(new QFilter("billstatus", QCP.equals, "C"))});
                        Map<String, Object> objectMap = initialize.getMoney(outbudgets);
                          num=+(Integer) objectMap.get("sum");
                        moneys =moneys.add((BigDecimal) objectMap.get("money"));
                        projectbudget=projectbudget.add(setId.getBigDecimal("projectbudget"));
                    }
                    map.put("ssxmmc", proName);//所属项目名称
                    map.put("yslb", initialize.getYslb(s)); //预算类别
                    //项目支出预算
                     map.put("ssxmyzbxmsl",num);//所属项目已招标项目数量
                }

                if ("0E-10".equals(projectbudget.toString())) {
                    map.put("ssxmyszje", "0");//最高限价
                } else {
                    map.put("ssxmyszje",projectbudget.setScale(2,BigDecimal.ROUND_HALF_UP) ); //所属项目预算总金额
                }

                if ("0E-10".equals(moneys.toString())) {
                    map.put("ssxmysyysje", "0");//所属项目已使用预算金额
                } else {
                    map.put("ssxmysyysje", moneys.setScale(2,BigDecimal.ROUND_HALF_UP));//所属项目已使用预算金额
                }


                BigDecimal singlemoney= single.getBigDecimal("money");
                if ("0E-10".equals(singlemoney.toString())) {
                    map.put("bxmzbysje", "0");//所属项目已使用预算金额
                } else {
                    map.put("bxmzbysje", singlemoney.setScale(2,BigDecimal.ROUND_HALF_UP));//本项目招标预算金额
                }

                map.put("lxspqk","已审批");
                map.put("kbsj","待定");


                if(single.getBoolean("zmee_ispaper")){
                    map.put("sfgg", "0");//是否公告
                }else {
                    map.put("sfgg", "1");//是否公告
                }

                map.put("zbfs", initialize.getZbfs(single.getString("sourcetype.number")));//招标方式
                BigDecimal money = single.getBigDecimal("money");
                if ("0E-10".equals(money.toString())) {
                    map.put("zgxj", "0");//最高限价
                } else {
                    map.put("zgxj",money.setScale(2,BigDecimal.ROUND_HALF_UP) );//最高限价
                }
                String biztypenumber = single.getString("biztype.number");

              //  if("1104".equals(biztypenumber)) {
                    map.put("zbdlgs",single.getString("zmee_combofield6"));//招标代理公司
                    map.put("sfszzgxj", single.getString("zmee_combofield"));//是否设置最高限价
                    map.put("psbf", single.getString("zmee_combofield1"));//评审办法
                    map.put("zbdlgsmc", single.getString("zmee_textfield"));//招标代理公司名称
                    map.put("cgggfbwz", single.getString("zmee_mulcombofield"));//采购公告发布网站
                    map.put("cglx", single.getString("zmee_combofield2"));//采购类型
                    map.put("ejlx", single.getString("zmee_combofield3"));//二级类型
                    map.put("bjfs", single.getString("zmee_combofield4"));//报价方式
                    map.put("sfzndysfwn", single.getString("zmee_combofield5"));//是否在年度预算范围内
                    map.put("lxjysqksm", single.getString("zmee_textareafield"));//立项及预算情况说明
                    map.put("xmgk", single.getString("zmee_textareafield1"));//项目概况
                    map.put("zbcgfw", single.getString("zmee_textareafield2"));//招标（采购）范围
                    map.put("zjcscx", single.getString("zmee_textareafield3"));//专家产生程序
                    map.put("zbcgr", single.getString("zmee_combofield7"));//招标（采购）人
                    map.put("htgsj", single.getString("zmee_textfield2"));//合同估算价
                    map.put("gyszgyq", single.getString("zmee_textareafield4"));//供应商资格要求
                    map.put("swzxf", single.getString("zmee_decimalfield"));//商务资信分
                    map.put("jsf", single.getString("zmee_decimalfield1"));//技术分
                    map.put("jgf", single.getString("zmee_decimalfield2"));//价格分
                    map.put("cgfsxysm", single.getString("zmee_textareafield5"));//采购方式选用说明
                    Date date = single.getDate("zmee_datefield1");
                    SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy-MM-dd");
                    if(date != null) {
                        String format = dateFormat.format(date);
                        map.put("jhsscgsj", format);//计划实施采购时间
                    }
                    map.put("bqzbqk",single.getString("zmee_textareafield7"));//标前准备情况
                    map.put("bdhf", single.getString("zmee_textareafield8"));//标段划分

                    map.put("qtszxtk",single.getString("zmee_textareafield6"));//其他实质性条款
                    Date datefield2 = single.getDate("zmee_datefield2");
                    if(datefield2 != null) {
                        String field2 = dateFormat.format(datefield2);
                        map.put("sqrq", field2);//申请日期
                    }
                    map.put("dlfy",single.getString("zmee_textfield3"));//代理费用
              //  }



                break;
            //项目立项
            case "pmas_pro_approval":

                map.put("barcode", billno);//单据编码
                DynamicObject department = single.getDynamicObject("department");
                if (department != null) {
                    DynamicObject org = BusinessDataServiceHelper.loadSingle(department.getPkValue(), department.getDynamicObjectType().getName());
                    map.put("ngbm", org.getString("oaid"));//实施组织/申请部门 名称
                }
                DynamicObject syscreateorg = single.getDynamicObject("syscreateorg");
                if (syscreateorg != null) {
                    DynamicObject org = BusinessDataServiceHelper.loadSingle(syscreateorg.getPkValue(), syscreateorg.getDynamicObjectType().getName());
                    map.put("ssdw", org.getString("oaid"));//管理单位/申请公司 名称
                }
                map.put("zs",single.getString("zmee_zs"));
                map.put("cs",single.getString("zmee_cs"));
                map.put("fwzh",single.getString("zmee_fwzh"));
                map.put("sourcefrom", "优采云");//系统来源
                map.put("sourfrom","2");
                map.put("fwlx",single.getString("zmee_fwlx"));
                map.put("jjcd",single.getString("zmee_jjcd"));
                map.put("ngr",single.getString("creator.oaid"));
                map.put("sourcefrom","优采云");
                break;
            //定标单
            case "src_decision":
                StringBuilder builder=new StringBuilder();
                String orgName=single.getString("org.name");//采购组织名称
                builder.append("【"+orgName+"】");
                String  sourceName=single.getString("source.title");//项目名称
                builder.append("【"+sourceName+"】");
                String  typeName=single.getString("sourcetype.name");//采购方式类型
                builder.append("【"+typeName+"】");
                builder.append("文件");
                map.put("title",builder.toString());//标题
                map.put("barcode",billno);//单据号
                map.put("xmbh",billno);//项目编码
                map.put("sourcefrom", "优采云");//系统来源
                map.put("gs",single.getString("org.oaid"));//所属公司
                map.put("tjr",single.getString("oasqr.oaid"));//提交人
                //userOrg.getString("dpt.oaid")
                map.put("tjbm",single.getString("oaorg.oaid"));//提交部门

                map.put("xmmc",sourceName);//项目名称
                DynamicObject srcDecisionsumSup = BusinessDataServiceHelper.loadSingle("src_decisionsum_sup",
                        "id", new QFilter("parentid", QCP.equals, single.getPkValue().toString()).toArray());
                if(srcDecisionsumSup!=null) {
                    DynamicObject[] decisionsumsup = BusinessDataServiceHelper.load("src_decisionsumsup",
                            "id,amount,supplier", new QFilter("billid", QCP.equals, srcDecisionsumSup.getPkValue().toString()).toArray());
                    StringBuilder supplierName=new StringBuilder();
                    for (int i = 0; i < decisionsumsup.length; i++) {
                        supplierName.append("【"+decisionsumsup[i].getString("supplier.name")+"】");
                    }
                    map.put("ndzbr",supplierName );//拟定中标人
                }
                //招标立项申请单
                DynamicObject sources = single.getDynamicObject("source");
                DynamicObject srcDemand = BusinessDataServiceHelper.loadSingle(sources.getString("number"), "src_demand");

                map.put("zbxmys", srcDemand.getBigDecimal("money").setScale(2,BigDecimal.ROUND_HALF_UP));//招标项目预算
               try {
                   DynamicObject pro_approval = srcDemand.getDynamicObject("pro_approval");
                   //获取项目支出预算
                   DynamicObject approval = BusinessDataServiceHelper.loadSingle(pro_approval.getPkValue(), pro_approval.getDynamicObjectType().getName());
                   DynamicObject pro = approval.getDynamicObject("project");
                   DynamicObject proOject = BusinessDataServiceHelper.loadSingle(pro.getPkValue(), pro.getDynamicObjectType().getName());
                   DynamicObject kind = proOject.getDynamicObject("group");
                   if(getInitialize().getKindNumber(kind.getString("number"))){
                       map.put("zbj", single.getBigDecimal("sumamount").setScale(2, BigDecimal.ROUND_HALF_UP));//中标价
                   }else {
                       map.put("zbj", single.getBigDecimal("sumtaxamount").setScale(2, BigDecimal.ROUND_HALF_UP));//中标价
                   }
               }catch (Exception e) {
                   logger.error(String.format("分类异常：%s",e));
                   map.put("zbj", single.getBigDecimal("sumtaxamount").setScale(2, BigDecimal.ROUND_HALF_UP));//中标价

               }

                break;
            //补充协议
            case "pmct_outaddagreement":
                //支出合同
                DynamicObject tract = single.getDynamicObject("contract");
                DynamicObject contract = BusinessDataServiceHelper.loadSingle(tract.getPkValue(), "pmct_outcontract");

                map.put("sqdw",single.getString("org.oaid"));//申请公司
                map.put("htbh",single.getString("billno"));//合同编号
                map.put("sqr",single.getString("sqr.oaid"));//申请人
                map.put("htcbbm",single.getString("htcbbm.oaid"));//合同承办部门
                map.put("htlx",contract.getString("zmee_contracttype"));//合同类型
                map.put("htbdje",single.getBigDecimal("addamountoftax").setScale(2,BigDecimal.ROUND_HALF_UP));//合同标的金额
                map.put("sfklx",contract.getString("zmee_accandpaytype"));//收付款类型
                map.put("sfkfs",contract.getString("zmee_accandpayway"));//收付款方式
                map.put("ssed",contract.getString("zmee_limitofcredit"));//授信额度（赊销及预付款）
                map.put("ysyed",contract.getBigDecimal("zmee_usedlimit").setScale(2,BigDecimal.ROUND_HALF_UP));//已使用额度
                map.put("ksyed",contract.getBigDecimal("zmee_uselimit").setScale(2,BigDecimal.ROUND_HALF_UP));//可使用额度
                map.put("bz",single.getString("description"));//备注
                map.put("sfwbcxy","1");
                Boolean isreport = single.getBoolean("sfyhsbm");
                if(isreport) {
                    map.put("sfyhsbm","0");//是否有会审部门
                    map.put("hsbm",single.getString("hsbm.oaid"));//会审部门
                }else{
                    map.put("sfyhsbm","1");//是否有会审部门
                }
                DynamicObject partbDy = contract.getDynamicObject("partb");
                if(partbDy != null){
                    map.put("htxdr",partbDy.getString("name"));//合同相对人
                }
                map.put("barcode",single.getString("billno"));//单据号
                map.put("sourcefrom","优采云");//单据号
                map.put("sourfrom","2");//单据号
                break;
        }

    }


    //环能本部表单数据
    public static Map<String,Object> getMainfieldParam(DynamicObject param,DynamicObject user){
        Map<String,Object> map=new HashMap<>();
        String name = param.getDynamicObjectType().getName();
        String bidname= param.getString("bidname");
        String billno = param.getString("billno");
        switch (name){
            case "src_biddoc":
                map.put("sqr", user.getString("oaid"));//申请人
                map.put("sqbm",param.getString("oaorg.oaid"));//申请部门
                map.put("barcode",billno);
                map.put("zblx","2");
                map.put("sourcefrom","优采云");
                break;
            case "src_decision":
                DynamicObject org = param.getDynamicObject("org");
                map.put("gs",org.getString("oaid"));//公司
                StringBuilder stringBuilder=new StringBuilder();
                stringBuilder.append("【"+org.getString("name")+"】");
                stringBuilder.append("【定标】");
                stringBuilder.append("【"+bidname+"】");
                stringBuilder.append("【"+billno+"】");
                map.put("title",stringBuilder.toString());//标题
                map.put("xmmc",bidname);//项目名称
                map.put("xmbh",billno);//项目编号
                map.put("barcode",billno);
                map.put("suoshugongs",org.getString("oaid"));//所属公司
                map.put("tjr",user.getString("oaid"));//提交人
                map.put("tjbm",param.getString("oaorg.oaid"));//提交部门

                map.put("sourcefrom","优采云");//单据来源
                DynamicObject srcDecisionsumSup = BusinessDataServiceHelper.loadSingle("src_decisionsum_sup",
                        "id", new QFilter("parentid", QCP.equals, param.getPkValue().toString()).toArray());
                if(srcDecisionsumSup!=null) {
                    DynamicObject[] decisionsumsup = BusinessDataServiceHelper.load("src_decisionsumsup",
                            "id,amount,supplier", new QFilter("billid", QCP.equals, srcDecisionsumSup.getPkValue().toString()).toArray());
                    StringBuilder supplierName=new StringBuilder();
                    for (int i = 0; i < decisionsumsup.length; i++) {
                        supplierName.append("【"+decisionsumsup[i].getString("supplier.name")+"】");
                    }
                    map.put("ndzbr",supplierName );//拟定中标人
                }
                //项目启动
                DynamicObject projects = BusinessDataServiceHelper.loadSingle("src_project", "id", new QFilter[]{new QFilter("billno", QCP.equals, billno)});
                DynamicObject srcProject = BusinessDataServiceHelper.loadSingle(projects.getPkValue(), "src_project");
                //招标立项申请单
                String number = srcProject.get("source.number").toString();
                DynamicObject srcDemand = BusinessDataServiceHelper.loadSingle(number, "src_demand");
                map.put("zbxmys", srcDemand.getBigDecimal("money").setScale(2,BigDecimal.ROUND_HALF_UP));//招标项目预算
                map.put("zbj",param.getBigDecimal("sumtaxamount").setScale(2,BigDecimal.ROUND_HALF_UP));//中标价

                break;
        }
        return map;
    }


    /**
    * 获取分录附件
    */
    public static List<Map<String,String>> getDatafieldMap(DynamicObject param){
        List<Map<String,String>> list=new ArrayList<>();
        String name = param.getDynamicObjectType().getName();
        DynamicObject single = BusinessDataServiceHelper.loadSingle(param.getPkValue(), name);
//        DynamicObject download = OARequestUtil.getInitialize().config("download");//地址配置

        OARequestUtil oaRequestUtil = new OARequestUtil();
        DynamicObject download = oaRequestUtil.config("download");
        String downloadURl = download.getString("url");//系统附件存放地址
        String loginToken = BosUtil.getLoginToken();
        switch (name){
            //标书编制
            case "src_biddoc":
                DynamicObject biddoc = BusinessDataServiceHelper.loadSingle("src_biddoc_src", "id", new QFilter[]{new QFilter("parentid", QCP.equals, single.getPkValue())});
                DynamicObject biddoc_src = BusinessDataServiceHelper.loadSingle(biddoc.getPkValue(), "src_biddoc_src");
                //分录
                DynamicObjectCollection entitys = biddoc_src.getDynamicObjectCollection("entryentity");
                    for (DynamicObject ent:entitys) {
                        //附件列表
                        DynamicObjectCollection bidattach = ent.getDynamicObjectCollection("bidattach");
                        for (int i = 0; i < bidattach.size(); i++) {
                            //获取单独字段
                            DynamicObject fbase=bidattach.get(i);
                            Map<String,String> urls=new HashMap();
                            DynamicObject attachment = BusinessDataServiceHelper.loadSingle(fbase.getDynamicObject("fbasedataid").getPkValue(), "bd_attachment");//附件实体
                            String url = attachment.getString("url");//附件相对路径
                            StringBuilder strurl=new StringBuilder();
                            strurl.append(downloadURl);
                            strurl.append(url);
                            strurl.append("&amp;access_token=");
                            strurl.append(loginToken);
                            //文件下载地址
                            urls.put("fieldName","zbwj" );
                            String names = attachment.getString("name");
                            String[] split = names.split("&");
                            StringBuffer urlname=new StringBuffer();
                            for (int j = 0; j < split.length; j++) {
                                if((j+1)==split.length){
                                    urlname.append(split[0]);
                                }else {
                                    urlname.append(split[0] + "&amp;");
                                }
                            }
                            urls.put("fieldType","http:"+urlname);
                            urls.put("fieldValue", strurl.toString());//招标文件
                            logger.info("====resultEnreyUrl===="+urls);
                            list.add(urls);
                        }
                    }
                break;
            case "pmas_pro_approval":
                DynamicObjectCollection attachtypeentry = single.getDynamicObjectCollection("attachtypeentry");
                for (DynamicObject attac:attachtypeentry) {
                    DynamicObjectCollection upfiles = attac.getDynamicObjectCollection("upfile");
                    for (int i = 0; i < upfiles.size(); i++) {
                        Map<String,String> map=new HashMap<>();
                        DynamicObject upfile = upfiles.get(i);
                        DynamicObject attachment = BusinessDataServiceHelper.loadSingle(upfile.getDynamicObject("fbasedataid").getPkValue(), "bd_attachment");
                        String url = attachment.getString("url");//附件相对路径
                        StringBuilder strurl=new StringBuilder();
                        strurl.append(downloadURl);
                        strurl.append(url);
                        strurl.append("&amp;access_token=");
                        strurl.append(loginToken);
                        map.put("fieldName","fj" );
                        String names = attachment.getString("name");
                        String[] split = names.split("&");
                        StringBuffer urlname=new StringBuffer();
                        for (int j = 0; j < split.length; j++) {
                            if((j+1)==split.length){
                                urlname.append(split[0]);
                            }else {
                                urlname.append(split[0] + "&amp;");
                            }
                        }
                        map.put("fieldType","http:"+urlname);
                        map.put("fieldValue",strurl.toString());//招标文件
                        list.add(map);
                    }
                }
                break;
             //定标单
            case "src_decision":

                break;
        }
        return list;
    }

    /**
    * 获取附件面板中的附件
    */
    public static List<Map<String,String>> urlList(List<Map<String, Object>> attachmentpanels,String txt){
        List<Map<String,String>> list=new ArrayList<>();
        for (int i = 0; i < attachmentpanels.size(); i++) {
            Map<String,String> maps=new HashMap<>();
            Map<String, Object> map = attachmentpanels.get(i);
            maps.put("fieldName",txt);
            String names = map.get("name").toString();
            String[] split = names.split("&");
            StringBuffer name=new StringBuffer();
            for (int j = 0; j < split.length; j++) {
                if((j+1)==split.length){
                    name.append(split[0]);
                }else {
                    name.append(split[0] + "&amp;");
                }
            }
            maps.put("fieldType","http:"+name);
            String url = map.get("url").toString();
            String substring = url.substring(0, url.indexOf("&") + 1);
            maps.put("fieldValue",substring+"amp;access_token="+BosUtil.getLoginToken());
            list.add(maps);
        }
        return list;
    }

    /**
    *标书编制预算类别
     */
    private String getYslb(String txt){
        switch (txt){
            case "10101":
            case "10102":
            case "10103":
            case "10104":
                return "0";//投资
            case "10303":
            case "10304":
                return "1";//日常维修预算
            case "10301":
            case "10302":
                return "2";//大修预算
            case "10201":
                return "3";//研发预算
            case "10601":
                return "4";//安全预算
            case "10501":
                return "5";//其他
            case "10305":
                return "6";//应急维修
            case "10401":
                return "7";//IT项目
            default:
                return null;
        }
    }


    /**
     *标书编制招标方式
     */
    private String getZbfs(String txt){
        switch (txt){
            case "C010405":
                return "0";
            case "C010406":
                return "1";
            case "C010415":
                return "2";
            case "C010418":
                return "3";
            case "C010407":
                return "4";
            case "C010416":
                return "5";
            case "C010417":
                return "6";
        }
        return null;
    }
    /**
    * 提交部门
    */
    public static DynamicObject getUserOrg(DynamicObjectCollection entitys){
        for (DynamicObject ent:entitys) {
            if(!ent.getBoolean("ispartjob")){
                return ent;
            }
        }
        return null;
    }

    private  Map<String,Object> getMoney(DynamicObject[] load){
        Map map=new HashMap();
        BigDecimal money=new BigDecimal("0.00");
        int i=0;
        for (DynamicObject row:load) {
            DynamicObject outbudget = BusinessDataServiceHelper.loadSingle(row.getPkValue(), row.getDynamicObjectType().getName());
            logger.info("===项目支出预算编码==="+outbudget.getString("billno"));
            if(outbudget.getBoolean("isvalid")) {
                DynamicObjectCollection treee = outbudget.getDynamicObjectCollection("treeentryentity");
                for (DynamicObject ema : treee) {
                    BigDecimal budgetamount = ema.getBigDecimal("budgetamount");//本阶段金额
                    BigDecimal budgetamoney = ema.getBigDecimal("budgetamoney");//当前版本余额
                    logger.info("==budgetamount=="+budgetamount);
                    logger.info("==budgetamount=="+budgetamoney);
                    money = money.add(budgetamount.subtract(budgetamoney));
                }
            }
            //招标立项申请单
            DynamicObject[] demands = BusinessDataServiceHelper.load("src_demand", "id",
                    new QFilter[]{new QFilter("pro_approval.id", QCP.equals, row.getPkValue() )
                            .and("billstatus",QCP.equals,"C")});
            i=i+demands.length;
        }
        map.put("sum",i);
        map.put("money",money);
        return map;
    }
    //价格排名方式
    private  String jgpmfs(String txt){
        switch (txt){
            case "1":
                return "最低值排名";
            case "2":
                return "最高值排名";
            case "3":
                return "平均值排名";
            case "4":
                return "随机排名(随机抽取)";
            case "5":
                return "基准值(起标价)";
            case "6":
                return "基准值(平均价)";
        }
        return null;
    }

    private Boolean getKindNumber(String number){
        try {
            switch (number){
                case "106":
                case "104":
                case "102":
                case "103":
                    return true;
            }

        DynamicObject kind = BusinessDataServiceHelper.loadSingle("bd_projectkind", "id,number,parent", new QFilter("number", QCP.equals, number).toArray());
        DynamicObject parent = kind.getDynamicObject("parent");
        String parentNumber = parent.getString("number");
        if( "0".equals(parentNumber) || parentNumber == null){
            return false;
        }
        return getKindNumber(parentNumber);
        }catch (Exception e){
            logger.error("=查询分类异常="+e);
            return false;
        }
    }



}
